<template>
  <el-select style="width:100%" filterable v-model="model" v-bind="$attrs" clearable v-on="$listeners">
    <template v-for="(item) of options">
      <el-option :key="item.id" :value="item.id" :label="item.projectName + '【 '+ item.ratedNum + '' + item.ratedUnitName +' 】'">
        <span style="float: left">{{ item.projectName }}</span>
        <span style="float: right; color: #8492a6; font-size: 13px">{{ item.ratedNum + '' + item.ratedUnitName }}</span>
      </el-option>
    </template>
  </el-select>
</template>

<script>
import { listQuantitativeType } from '@/api/cases/quantitativeType'
export default {
  model: {
    prop: "value",
    event: "change"
  },
  data() {
    return {
      options: []
    }
  },
  props: {
    value: {
      type: String,
      default:  void 0
    },
    checkTypeId:{
      type: [String,Number],
      default: void 0
    }
  },
  computed: {
    model: {
      get() {
        return this.value ? this.value : void 0
      },
      set(value) {
        this.$emit("change", value)
      }
    }
  },
  watch:{
    checkTypeId(){
      if(this.checkTypeId){
        this.getList();
      }else{
         this.options = [];
      }
    }
  },
  async mounted() {
    this.getList();
  },
  methods: {
    /**
     * 清理值
     */
    clear(){
      this.$emit("change", void 0);
    },
    /**
     * 获取类型
     */
    getList() {
      let params = {
        status: 0,
        delFlag:0,
        checkTypeId: this.checkTypeId,
        pageSize: 99999
      }
      listQuantitativeType(params).then(res => {
        this.options = res.rows;
      }).catch(error => {
        this.options = []
      })
    },
    /**
     * 获取排查类型
     */
    getQuantitativeTypeById(id){
      return this.options.find(item=>{
        return item.id == id;
      })
    }
  }
}
</script>

<style>
</style>